/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.tedu.mall.sso.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service("localCode")
@Slf4j
public class LocalCodeServiceImpl extends AbstractCodeService {

    @Autowired
    private StringRedisTemplate redisTemplate;

    /*@Override
    public void sendCode(String phoneNum) {
        super.setRedisTemplate(redisTemplate);
        //电话号码校验
        validatePhone(phoneNum);
        //检查锁是否存在，存在则已经锁定电话号码
        lockCheck(phoneNum);
        //没有锁定，验证本次是否违反规则
        String code = generateCode(phoneNum);
        //发送验证码到手机
        send(phoneNum, code);
    }*/

    private void send(String phoneNum, String code) {
        log.info("当前手机号:{},收到验证码:{}", phoneNum, code);
    }

    @Override public void sendCode(String phoneNum, String validCode, String validCodeId,String ip) {
        super.setRedisTemplate(redisTemplate);
        validatePhone(phoneNum);
        checkValidCode(validCode,validCodeId,ip);
        lockCheck(phoneNum);
        String code = generateCode(phoneNum);
        //验证一下validcodeId validCode
        send(phoneNum,code);
    }
}
